package com.ruoyi.frame.config;

import com.ruoyi.frame.spring.intercept.LogHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * WebMvcConfigurer实现类: 用于自定义配置拦截器、资源等等
 *
 * @author zengxiangjiang
 * @version 1.0.0
 */
@Configuration
public class ZengWebMvcConfigurer implements WebMvcConfigurer {

    @Resource
    private LogHandlerInterceptor logHandlerInterceptor;

    /**
     * 自定义拦截器
     *
     * @param registry 拦截器注册
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 多个拦截器组成一个拦截器链
        // 自定义拦截器，添加拦截路径和排除拦截路径
        // addPathPatterns 用于添加拦截规则, /**表示拦截所有请求, .excludePathPatterns("/api","/account/register") 用户排除拦截
        registry.addInterceptor(logHandlerInterceptor).addPathPatterns("/**").excludePathPatterns("/ajax/**", "/ruoyi/**", "/js/**", "/css/**", "/fonts/**");
    }

}
